package com.dianning.web.taglib;

import java.io.IOException;
import java.io.Writer;
import java.util.*;

import javax.servlet.jsp.PageContext;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.components.Component;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.dianning.bean.Info;
import com.dianning.comm.Constant;
import com.opensymphony.xwork2.util.ValueStack;

public class InfoPic extends Component {

	private PageContext pageContext;

	private String value;

	public InfoPic(ValueStack stack, PageContext pageContext) {
		super(stack);
		this.pageContext = pageContext;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public boolean start(Writer writer) {
		boolean result = super.start(writer);
		WebApplicationContext wc = WebApplicationContextUtils.getWebApplicationContext(this.pageContext
				.getServletContext());
		if (value == null) {
			value = "top";
		} else if (altSyntax()) {
			if (value.startsWith("%{") && value.endsWith("}")) {
				value = value.substring(2, value.length() - 1);
			}
		}
		String pic = (String) this.getStack().findValue(value);	
		pic = StringUtils.trim(pic);
		pic = StringUtils.trimToEmpty(pic);
		try {
			writer.write(pic);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return result;
	}

}
